package cn.livingCloud.entity.user;

import cn.livingCloud.context.BeanProvider;
import cn.livingCloud.repository.UserMapper;
import cn.livingCloud.utils.UuidGenerator;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class User implements Serializable {
    private transient UserMapper userMapper = BeanProvider.getBean(UserMapper.class);

    protected String uuid = UuidGenerator.generate();
    protected String name;

    private List<UserAccount> userAccountList = new ArrayList<UserAccount>();

    public User() {
    }

    public User(String name) {
        this.name = name;
    }

    public String getUuid() {
        return uuid;
    }

    @SuppressWarnings("unchecked")
    public <T extends User> T setUuid(String uuid) {
        this.uuid = uuid;
        return (T) this;
    }

    public String getName() {
        return name;
    }

    @SuppressWarnings("unchecked")
    public <T extends User> T setName(String name) {
        this.name = name;
        return (T) this;
    }

    public List<UserAccount> getUserAccountList() {
        return userAccountList;
    }

    public User setUserAccountList(List<UserAccount> userAccountList) {
        this.userAccountList = userAccountList;
        return this;
    }

    public User save() {
        userMapper.save(this);
        return this;
    }

    public User update() {
        userMapper.update(this);
        return this;
    }

    @Override
    public String toString() {
        return "User{" +
                "userMapper=" + userMapper +
                ", uuid='" + uuid + '\'' +
                ", name='" + name + '\'' +
                ", userAccountList=" + userAccountList +
                '}';
    }
}
